package moddbbackendrevisited;

import com.sun.grizzly.http.SelectorThread;
import com.sun.jersey.api.container.grizzly.GrizzlyWebContainerFactory;
import java.io.IOException;
import java.net.URI;
import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.ws.rs.core.UriBuilder;

public class Main {
  
  private static Driver jdbcDriver;
  public static Connection dbCon;

  static {
    try {
      // MS SQLServer 2005
      //jdbcDriver = (Driver) Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver").newInstance();
      //dbCon =  DriverManager.getConnection("jdbc:sqlserver://10.0.1.197:1433;databaseName=moddb", "moddb", "enduro");
      
      // sqlite
      jdbcDriver = (Driver) Class.forName("org.sqlite.JDBC").newInstance();
      dbCon = DriverManager.getConnection("jdbc:sqlite:test.db");

      if (dbCon != null) {
          System.out.println("Connection to the Database Successful!");
      }

    } catch (Exception e) {
      e.printStackTrace();
      System.exit(1);
    }
  }

  /**
    * @param args the command line arguments
    */
  public static void main(String[] args) throws IOException {

    final String baseUri = "http://localhost:9998/";
		final Map<String, String> initParams = new HashMap<String, String>();

		initParams.put("com.sun.jersey.config.property.packages", "moddbbackendrevisited.resource");

		System.out.println("Starting Web Server (grizzly)...");
		SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams);
		//System.out.println(String.format("Jersey app started with WADL available at %sapplication.wadl\n" +
		//								 "Try out %shelloworld\nHit enter to stop it...", baseUri, baseUri));
    System.out.println("Hit enter to stop it...");
    System.in.read();
        
		threadSelector.stopEndpoint();
		System.exit(0);
  }
}
